#include<stdio.h>
#include<string.h>
#include<ctype.h>
int size=0;
struct data{
        char name[20];
        char pass[20];
        }hash[100];

int h(char k[], int i)
{
        int l;
        l=strlen(k);
        return (l+i)%10;
        
}
int h_insert(char n[],char p[])
{
        int i=0;
        int j;
        do{
                j=h(n,i);
                if(strcmp(hash[j].name,"")==0)
                        {strcpy(hash[j].name,n);
                        strcpy(hash[j].pass,p);
                        return j;
                                }
                else            
                        i=i+1;
        }while(i<size);
        return -1;
}




int h_search(char n[], char p[])
{
        int i,j; 
        
        i=0;
        do{
                j=h(n,i);
                if(strcmp(hash[j].name,n)==0) 
                        if(strcmp(hash[j].pass,p)==0)
                                return j;
                
                i=i+1;
        }while((strcmp(hash[j].name,"")!=0)&&(i<size));
        return -1;
} 

int main()
{       int i,k,c,j,flag;
        char name[20],pass[20];
        char n1[20];
        char p[20];
        FILE *f,*fp1;



        fp1=fopen("abhi.txt","r");
    c=getc(fp1);
    while(c!=EOF)
    {
        if(c=='\n')
        {
            size++; 
        }
            c=getc(fp1);   
     
        }
        size=(20+size);
        
        f=fopen("abhi.txt","r");
        for(i=0;fscanf(f,"%s %s",name,pass)!= EOF;i++)
                h_insert(name,pass);
        
        for(j=0;j<3;j++)
        {
       	printf("login number %d : \n",(j+1));
        printf("Enter the username \n");
        scanf(" %s",n1);
        printf("Enter the password \n");
        scanf(" %s",p);
        flag=h_search(n1,p);
        if(flag==-1)
        printf("login failed \n");
        else{
        printf("login successful \n");
        break;
        }
        }
        if(flag==-1)
        printf("too many tries... \n");
return -1;
}
